<?php
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
# ***** BEGIN LICENSE BLOCK *****
# This file is part of Plume Framework, a simple PHP Application Framework.
# Copyright (C) 2001-2006 Loic d'Anterroches and contributors.
#
# Plume Framework is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Plume Framework is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#
# ***** END LICENSE BLOCK ***** */

class Admin_Paginator extends Pluf_Paginator
{
    /**
     * Generate a standard "line" of the body
     */
    function bodyLine($item)
    {
        $out = '<tr>';
        if (!empty($this->list_display)) {
            $i = 0;
            foreach ($this->list_display as $key=>$col) {
                $bools = array();
                $fks = array();
                if (!is_array($col)) {
                    $field = Pluf::factory($this->model->_a['cols'][$key]['type']);
                    if ($field->type == 'boolean') {
                        $bools[] = $key;
                    } elseif ($field->type == 'foreignkey') {
                        $fks[] = $key;
                    }
                }
                $text = '';
                if (!is_array($col)) {
                    if (in_array($key, $bools)) {
                        $img = Pluf_Template_Tag_MediaUrl::url('/admin/img/'.(($item->$key) ? 'check_on.png' : 'check_off.png'));
                        $text = '<img src="'.$img.'" alt="'.Pluf_esc($item->$key).'" />';
                    } elseif (in_array($key, $fks)) {
                        $_method = 'get_'.$key;
                        $text = Pluf_esc($item->$_method());
                    } else {
                        $text = Pluf_esc($item->$key);
                    }
                } else {
                    if (is_null($this->extra)) {
                        $text = $col[1]($col[0], $item);
                    } else {
                        $text = $col[1]($col[0], $item, $this->extra);
                    }
                }
                if ($i == 0) {
                    $text = $this->getEditAction($text, $item);
                }
                $out.='<td>'.$text.'</td>';
                $i++;
            }
        } else {
            $out.='<td>'.$this->getEditAction(Pluf_esc($item), $item).'</td>';
        }
        $out .= '</tr>'."\n";
        return $out;
    }
}
